package day7;

import java.util.*;

public class Parenthesis {
    public static boolean chkParenthesis(String A, int n) {
        if(n%2!=0){
            return false;
        }
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<n;i++){
            if(A.charAt(i)=='('){
                stack.push(A.charAt(i));
            }else if(A.charAt(i)==')'){
                if(stack.empty()){
                    return false;
                }
                stack.pop();
            }
            else
                return false;
        }
        return stack.empty()?true:false;
    }

    public static void main(String[] args) {
        System.out.println(chkParenthesis("()()(((())))",12));
    }
}